package com.atguigu.mapreduce.flowcount.partition;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

public class FlowPartitioner extends Partitioner<Text, FlowBean> {

    // 自定义分区规则 136 137 138 139 other
    @Override
    public int getPartition(Text text, FlowBean flowBean, int numPartitions) {
        String phoneNumber = text.toString();
        int partitions;
        if (phoneNumber.startsWith("136")) {
            partitions = 0;
        } else if (phoneNumber.startsWith("137")) {
            partitions = 1;
        } else if (phoneNumber.startsWith("138")) {
            partitions = 2;
        } else if (phoneNumber.startsWith("139")) {
            partitions = 3;
        } else {
            partitions = 4;
        }
        return partitions;
    }
}
